package com.fateai.module;

import android.os.Bundle;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fateai.module.swipeItemHelper.MyAdapter;
import com.fateai.module.swipeItemHelper.SwipeMenuHelper;
import com.fateai.module.swipeItemHelper.TestDataGenerator;
import com.fateai.module.swipeItemHelper.UserData;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private MyAdapter adapter;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        recyclerView = findViewById(R.id.recycler_view);
        // 设置线性布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        // 可选：设置为水平方向（默认是垂直方向）
        // layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);

        List<UserData> testUsers = TestDataGenerator.generateTestUsers(100);
        adapter = new MyAdapter(testUsers);

        // 初始化 SwipeMenuHelper
        SwipeMenuHelper<MyAdapter.MyViewHolder> swipeHelper =
                new SwipeMenuHelper<>(recyclerView);

        // 设置菜单项点击监听器
        adapter.setOnMenuItemClickListener((position, menuItemId) -> {
            // 根据菜单项ID处理不同操作
            if (menuItemId == R.id.btn_edit) {
                handleEdit(position);
            } else if (menuItemId == R.id.btn_delete) {
                handleDelete(position);
            } else if (menuItemId == R.id.btn_share) {
                handleShare(position);
            }
        });

        recyclerView.setAdapter(adapter);
    }

    private void handleEdit(int position) {
        Toast.makeText(this, "编辑位置: " + position, Toast.LENGTH_SHORT).show();
        // 编辑逻辑...
    }

    private void handleDelete(int position) {
        adapter.removeAt(position);
        // 删除逻辑...
    }

    private void handleShare(int position) {
        Toast.makeText(this, "分享位置: " + position, Toast.LENGTH_SHORT).show();
        // 分享逻辑...
    }
}